/**
 * Created by longgs on 2018-7-18.
 */
angular.module('MetronicApp').controller('AlgorithmEditController',
    ['$rootScope', '$scope', '$state', '$uibModal', '$stateParams', 'toastr', 'AlgorithmService',
        function ($rootScope, $scope, $state, $uibModal, $stateParams, toastr, AlgorithmService) {
            $scope.$on('$viewContentLoaded', function () {
                App.initAjax();
                $rootScope.settings.layout.pageBodySolid = true;
                $rootScope.settings.layout.pageSidebarClosed = false;
            });

            $scope.id = $stateParams.id;
            $scope.condition = {};

            //企业画像表头五个tab数据获取
            $scope.tabItemList = [
                {
                    "name": "标签体系",
                    "router": "labelSystemList",
                    "selected": false
                },
                {
                    "name": "企业信息",
                    "router": "informationList",
                    "selected": false
                },
                {
                    "name": "挖掘算法",
                    "router": "algorithmList",
                    "selected": true
                },
                {
                    "name": "企业画像",
                    "router": "businessPortraitList",
                    "selected": false
                },
                {
                    "name": "标签检索",
                    "router": "labelRetrievalList",
                    "selected": false
                }
            ];

                $scope.baseEdit = true;

            //返回
            $scope.back = function () {

                $state.go('algorithmList');
            };
            //提交表单
            $scope.ldSubmit = function (form) {
                //处理表数据
                form.$submitted = true;
                if (form.$valid) {
                    AlgorithmService.save($scope.model).$promise.then(function (result) {
                        if ("success" == result.status) {
                            toastr.success("", "信息保存成功");
                            $state.go('algorithmList');
                        } else {
                            toastr.error("", result.message);
                        }

                    });
                }else{
                    toastr.error("", "请输入正确且完整的信息");
                }

            };
            //重置表单
            $scope.reset = function () {
                //处理表数据
                //document.getElementById("myForm").reset()
               if($scope.id){

                   angular.copy($scope.copyModel,$scope.model)
               }
               else{
                   $scope.model={};
               }

            };
            //详情
            if ($scope.id) {
                AlgorithmService.get($scope.id).$promise.then(function (result) {
                    $scope.model = result.data;

                       $scope.copyModel=angular.copy($scope.model  );

                });
            }


        }
    ]
);